<template>
  <div>
    <h1>登录</h1>
    <el-input v-model="params.username" placeholder="请输入账号" style="width: 350px"></el-input><br>
    <br>
    <el-input v-model="params.password" placeholder="请输入密码" show-password style="width: 350px"></el-input><br>
    <br>
    <el-button type="primary" icon="el-icon-position" round @click="login()" style="width: 200px">点击登录</el-button>
  </div>
</template>

<script>
export default {
  name: "Main",
  created() {

  },
  data(){
  return{
    params:{username:"",password:"", grant_type: 'password', client_id: 'aaa', client_secret: 111}
  }
  },
  methods:{
    login(){
      this.$http.post("authserver/oauth/token",this.params).then(data=>{
        console.log(data)
        if (data.code==200){
          alert("登录成功")
          //把token值存到session中
          sessionStorage.setItem('token',this.$qs.stringify(data.data))
          //把用户的uid存在store中
          this.$store.commit('setUser',data.data)
          //把刷新token的值存入state
          this.$store.commit("setClient",this.params)
          this.$router.push("/index")
        }else if (data.code==203){
          alert("账号或者密码不正确")
        }else if (data.code==206){
          alert("用户已被禁用")
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
